//
//  LYDNavgationBaseViewController.m
//  20150809生活圈
//
//  Created by yons on 15-8-9.
//  Copyright (c) 2015年 iron. All rights reserved.
//

#import "LYDNavgationBaseViewController.h"

#define navButtonHeight 44
#define navButtonWidth 44
@interface LYDNavgationBaseViewController ()

@end

@implementation LYDNavgationBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    _navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, UINavHeight)];
    _navView.backgroundColor = [UIColor colorWithRed:45 / 255.f green:156 / 255.f blue:239 / 255.f alpha:1];
    [self.view addSubview:_navView];

    _leftButton = [[UIButton alloc] init];
    _leftButton.frame = CGRectMake(0, UIStatusBarHeight, navButtonWidth, navButtonHeight);
    [_leftButton setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
    [_leftButton addTarget:self action:@selector(leftButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    [self.navView addSubview:_leftButton];
    _leftButton.hidden = YES;
    zzz
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    _titleLabel.text = @"你没有赋值";
    _titleLabel.textColor = [UIColor whiteColor];
    [_titleLabel setFont:[UIFont systemFontOfSize:20.0]];
    [self.navView addSubview:_titleLabel];
    
    _rightButton = [[UIButton alloc] init];
    [_rightButton addTarget:self action:@selector(rightButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    [self.navView addSubview:_rightButton];
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSMutableDictionary *attribute = [NSMutableDictionary dictionary];
    attribute[NSFontAttributeName] = [UIFont systemFontOfSize:20.0];
    CGRect titleRect = [self.titleLabel.text boundingRectWithSize:CGSizeZero options:NSStringDrawingUsesLineFragmentOrigin attributes:attribute  context:nil];
    _titleLabel.frame = CGRectMake((UIScreenWidth - titleRect.size.width) / 2, UIStatusBarHeight + (navButtonHeight - titleRect.size.height) / 2, titleRect.size.width, titleRect.size.height);
    
    if (/* DISABLES CODE */ (NO)) {
        [_rightButton setBackgroundImage:[UIImage imageNamed:@"nav_user"] forState:UIControlStateNormal];
        [_rightButton setTitle:@"" forState:UIControlStateNormal];
        _rightButton.frame = CGRectMake(UIScreenWidth - navButtonWidth, UIStatusBarHeight, navButtonWidth, navButtonHeight);
    }
    else
    {
        [_rightButton setBackgroundImage:nil forState:UIControlStateNormal];
        [_rightButton setTitle:@"登录/注册" forState:UIControlStateNormal];
        _rightButton.titleLabel.font = [UIFont systemFontOfSize:16.0];
        _rightButton.frame = CGRectMake(UIScreenWidth - navButtonWidth * 2, UIStatusBarHeight, navButtonWidth * 2, navButtonHeight);
    }
}

- (void)leftButtonDidClick
{
    
}

- (void)rightButtonDidClick
{
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
